package com.jxpanda.spring.module.auth.core.authentication.token;

import com.jxpanda.spring.module.auth.endpoint.OAuth2Request;
import org.springframework.security.oauth2.client.authentication.OAuth2LoginAuthenticationToken;
import org.springframework.security.oauth2.client.registration.ClientRegistration;
import org.springframework.security.oauth2.core.user.OAuth2User;

public class OAuth2UserCollaborativeAuthenticationToken extends CollaborativeAuthenticationToken {

    private final OAuth2User principal;

    public OAuth2UserCollaborativeAuthenticationToken(OAuth2Request oAuth2Request, ClientRegistration clientRegistration, OAuth2User oAuth2User) {
        super(oAuth2Request, clientRegistration);
        this.principal = oAuth2User;
        this.setAuthenticated(true);
    }

    public OAuth2UserCollaborativeAuthenticationToken(OAuth2Request oAuth2Request, ClientRegistration clientRegistration, OAuth2LoginAuthenticationToken oAuth2LoginAuthenticationToken) {
        this(oAuth2Request, clientRegistration, oAuth2LoginAuthenticationToken.getPrincipal());
    }

    @Override
    public OAuth2User getPrincipal() {
        return this.principal;
    }

}
